package com.xyhuo.leetcode.november;

/**
 * 打家劫舍
 * https://leetcode.cn/problems/house-robber
 *
 * @time 2023/11/22
 */
public class Rob {

//    public static void main(String[] args) {
//        int[] nums = {2, 7, 9, 3, 1};
//        Rob rob = new Rob();
//        int result = rob.rob(nums);
//        System.out.println(result);
//    }

    public int rob(int[] nums) {
        int length = nums.length;
        int[] dp = new int[length];
        dp[0] = nums[0];
        for (int i = 1; i < length; i++) {
            int tmp = 0;
            for (int j = 0; j < i - 1; j++) {
                if (dp[j] > tmp) {
                    tmp = dp[j];
                }
            }
            dp[i] = nums[i] + tmp;
        }
        int result = dp[0];
        for (int i = 1; i < length; i++) {
            if (dp[i] > result) {
                result = dp[i];
            }
        }
        return result;

    }
}
